Ccay.Module.define("Ccay.example.ui.dataBind",function(page,$S){
		var demo1=false,demo2=false,demo3=false;
		page.ready=function(){
			$("#dataBindDemo").ccayTab({
				fnAfterSelectItem:function(tabid){
					initChart(tabid);
				}
		});
		
		function initChart(tabid){
			if(tabid=="demo1" && demo1==false){
				var lines = [{data: [[0, 3], [4, 8], [8, 5], [9, 13]], label: 'line1'},
	                 {data: [[0, 12], [7, 12], null, [7, 2.5], [12, 2.5]], label: 'line2'}];
	
	 			$("#chart").chart({lines : lines});
	 			demo1 = true;
			};
			if(tabid=="demo2" && demo2==false){
				demo2 = true;
				var datas = [
		           {month:1,profit:2000,total:4000},
		           {month:2,profit:4000,total:5000},
		           {month:3,profit:6000,total:9000},
		           {month:4,profit:10000,total:15000},
		           {month:5,profit:3000,total:7000},
		           {month:6,profit:2000,total:5000},
		           {month:7,profit:1000,total:4000},
		           {month:8,profit:5000,total:8000}
			    ];
				$('#chart2').chart({
					lines:[{label: '月度利润',xField:'month',yField:'profit',lines:{fill:true,steps: true}},
					       {label: '月度销售额',xField:'month',yField:'total',lines: { fill: true,steps: true }},
					       {label: '月度支出',lines: { fill: true,steps: true },fnSetData:function(item){
					    	   return [item.month,item.profit - item.total]
					       } }
					],
					ajax:{
						getData:function(success){
							success(datas);
						}
					}
				});
				
			};
			if(tabid=="demo3" && demo3 == false){
				demo3 = true;
				$("#chart3").chart({
				  	width:600,
					lines:[{label: '2011利润',bars: { show: true }},
					       {label: '2012利润',bars: { show: true }}
					], 
					ajax:{
						url:'ccay/example/ui/chart/datas.json',
						filter :function(data){
							var result = data.result,year,date,line1 =[],line2=[];
							
							$.each(result,function(i,item){
								date = item.date.toDate();
								if(date.getYear() == 2011)
									line1.push([date.getMonth() + 1,item.profit]);
								else
									line2.push([date.getMonth() + 1,item.profit]);
							});
							return [line1,line2];
						}
					},
					setting:{
						xaxis:{tickSize:1,min:1,max:12}
						
					}
				  });
				  
			}
		}
		
	};
	
});